#include "logger.h"

//QT
#include<QDateTime>

Logger *Logger::m_instance = 0;

void Logger::setOutput(QTextStream *textStream) {
    this->textStream = textStream;
}

void Logger::setLevel(int level = 2) {
    this->level = level;
}

void Logger::log(QString message, int level = 2) {
    if (level >= this->level) {
       QDateTime time = QDateTime::currentDateTime();
       *this->textStream << time.toString("yyyy.MM.dd hh:mm:ss ");
       switch(level) {
       case Logger::DEBUG:
           *this->textStream << "DEBUG: ";
           break;
       case Logger::NOTICE:
           *this->textStream << "NOTIC: ";
           break;
       case Logger::WARNING:
           *this->textStream << "WARNI: ";
           break;
       case Logger::ERROR:
           *this->textStream << "ERROR: ";
           break;
       default:
           *this->textStream << "UNKNO: ";
           break;
       }
       *this->textStream << message << endl;
    }
}

